<?php

class URL {

    public static function to($uri)
    {
	return HOST_PATH . BASE_PATH . $uri;
    }

    public static function reverse($url)
    {
	return str_replace(array(HOST_PATH, BASE_PATH), '', $url);
    }

    public static function redirect($url, $method = 'location', $delay = 0)
    {
	if (!preg_match('#^https?://#i', $url))
	{
	    $url = self::to($url);
	}

	switch ($method)
	{
	    case 'refresh' : header("Refresh:" . $delay . ";url=" . $url);
		break;
	    default : header("Location: " . $url, TRUE);
		break;
	}
	exit;
    }

    public static function get_url()
    {
	$url_string = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : @getenv('REQUEST_URI');
	return $url_string;
    }

}